############# ########### ####### ##### ### ##
#
# Copyright (C) 2010 The Hursk Group, LLC
#
# This program is free software: you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (See file named COPYING).  If not, see 
# <http://www.gnu.org/licenses/>.
# 
############# ########### ####### ##### ### ##

#!/bin/bash
#
#
# full relative to this script path to dir containing system data to be assessed
base_url=/path/to/unix/
# path to patchdiag.xref get it here --> http://sunsolve.sun.com/patchdiag.xref
patchdiag=./patchdiag.xref


# create list of security patches by parsing the patchdiag file
cat $patchdiag | grep "|S|" | grep -v "|O|" | cut -f1,2 -d"|" | sort -u > security_patches

#
# 
#
for host_name in `ls $base_url`
do
	if [ -f $base_url$host_name/showrevp.out ]; then
		for patch_item in `cat $base_url$host_name/showrevp.out | cut -f2 -d" "`
		do
			# get the patch number with out version
			patch_parent=`echo $patch_item | cut -f1 -d"-"`
			# get patch version
			patch_version=`echo $patch_item | cut -f2 -d"-"`
			
			for patch_hit in `cat ./security_patches | grep $patch_parent`
			do
				s_patch_parent=`echo $patch_hit | cut -f1 -d"|"`
				s_patch_version=`echo $patch_hit | cut -f2 -d"|"`
				#echo $s_patch_parent
				#echo $s_patch_parent_version
				if [ "$patch_version" -lt "$s_patch_version" ]; then
					echo $host_name,$patch_parent-$patch_version,$s_patch_parent-$s_patch_version
				fi
			done
			#diag_patch_parent=`cat $patchdiag | cut -f1 -d"|" | grep $patch_parent | cut -f1,2 -d"|"`
			#echo $diag_patch_parent
			#echo "now"
			#diag_patch_parent
			#echo $host_name,$patch_item >> consolidated_host_patch.txt
		done
	fi
done